/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2019-03-07 20:06:20
 * @LastEditors: kl2018
 * @LastEditTime: 2020-08-10 14:26:52
 */
import { observable, action } from 'mobx';
import { WeaTableNew, WeaForm } from 'comsMobx';
import * as Api from './../apis/loginLogApi';

const { TableStore } = WeaTableNew;
class LoginLogStore {
  @observable topTab = [];
  @observable selectedKey = '0';
  @observable logTableStore = new TableStore();
  @observable groupid = '0';
  @observable searchForm = new WeaForm();
  @observable showSearchAd = false

  @action.bound changeDate(v) {
    this.selectedKey = v;
    for (let list of this.topTab) {
      if (list.viewcondition == v) {
        this.groupid = list.groupid;
        break;
      }
    }
    this.getLogTableData();
  }

  @action.bound getTabData() {
    Api.getTabData().then((data) => {
      this.topTab = data.topTab;
    });
  }

  @action.bound getSearchData(text = '') {
    const params = {
      groupid: '0',
      userid: text,
      startDate: '',
      endDate: '',
    };
    Api.getLogTableData(params).then((data) => {
      if (data.sessionkey) {
        this.logTableStore.getDatas(data.sessionkey, 1, 10);
        this.groupid = '';
        this.showSearchAd = false;
        this.selectedKey = '0';
      }
    });
  }

  // 获取初始table
  @action.bound getLogTableData() {
    const params = { groupid: this.groupid };
    Api.getLogTableData(params).then((data) => {
      if (data.sessionkey) {
        this.logTableStore.getDatas(data.sessionkey, 1, 10);
      }
    });
  }

  @action.bound showSearchDrop() {
    this.showSearchAd = !this.showSearchAd;
    this.searchForm.resetForm();
  }

  @action.bound getSearchForm() {
    Api.getSearchForm().then((data) => {
      this.searchForm.setCondition(data.items);
    });
  }
}
export default new LoginLogStore();
